package com.jewel.service.impl;

import com.jewel.mapper.TabBlockMapper;
import com.jewel.mapper.TabProductMapper;
import com.jewel.model.Product;
import com.jewel.pojo.TabBlock;
import com.jewel.pojo.TabProduct;
import com.jewel.service.ProductService;
import com.jewel.tools.Tools;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 产品业务类
 * 
 * @author DELL
 *
 * @since 2017.04.27
 */
@Service
public class ProductServiceImpl implements ProductService {


    @Autowired
    private TabProductMapper tabProductMapper;

    @Autowired
    private TabBlockMapper tabBlockMapper;

    /**
	 * @Title: getProductById
	 * @Description：获取指定id产品
	 * 
	 * @param productId
	 * @return Product
	 * @throws：
	 * 
	 */
    @Override
    public Product getProductById(int productId) {
        Product product = null;

        TabProduct tabProduct = this.tabProductMapper.selectByPrimaryKey(productId);
        TabBlock tabBlock = this.tabBlockMapper.selectByPrimaryKey(tabProduct.getBlockId());

        if (!Tools.objectIsNullOrNot(tabBlock) && !Tools.objectIsNullOrNot(tabProduct)){
            product = new Product();

            product.setName(tabProduct.getName());
            product.setDescribes(tabProduct.getDescribes());
            product.setText(tabProduct.getText());
            product.setCommentNumber(tabProduct.getCommentNumber());
            product.setBlockName(tabBlock.getName());
            product.setPrice(tabProduct.getPrice());
            product.setOldPrice(tabProduct.getOldPrice());
        }

        return product;
    }


}
